from django.contrib import admin
from .models import Movie, UserMoviePreferences


@admin.register(Movie)
class MovieAdmin(admin.ModelAdmin):
    """电影模型的管理界面配置"""

    # 列表页面显示的字段
    list_display = ("id", "title", "country", "release_year", "genres")

    # 可搜索的字段
    search_fields = ("title", "country")

    # 过滤器字段
    list_filter = ("genres", "country", "release_year")

    # 每页显示的记录数
    list_per_page = 20

    # 排序字段
    ordering = ("id",)

    # 详细页面的字段分组
    fieldsets = (
        ("基本信息", {
            "fields": ("title", "country", "release_year")
        }),
        ("分类信息", {
            "fields": ("genres", "extra_data")
        }),
    )


@admin.register(UserMoviePreferences)
class UserMoviePreferencesAdmin(admin.ModelAdmin):
    """用户电影偏好模型的管理界面配置"""

    # 列表页面显示的字段
    list_display = ("id", "user", "preferences", "watch_history")

    # 可搜索的字段
    search_fields = ("user__username",)

    # 每页显示的记录数
    list_per_page = 20

    # 排序字段
    ordering = ("id",)
